package cn.wolfcode.luowowo.mgrsite.web;

import cn.wolfcode.luowowo.util.UploadUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@Controller
public class UploadController {
    @Value( "${file.path}" )
    private String filePath;
    @RequestMapping("/uploadImg")
    @ResponseBody
    private Object uploadImg(MultipartFile pic){
        String filename = UploadUtil.upload( pic, filePath );
        return filename;

    }
    @RequestMapping("uploadImg_ck")
    @ResponseBody
    public Map<String,Object> uploadEditor(MultipartFile upload){
        Map<String,Object> map = new HashMap<>();
        try {
            String filename = UploadUtil.upload( upload, filePath );
            map.put("uploaded",1);
            map.put("url","/"+filename);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("uploaded",0);
            map.put("msg","服务器空间不足，上传失败");
        }
        return map;
    }
}
